<?php
class CampAction extends AppAction {
	private $campLib;
	private $adminGrand;
	function __construct() {
		parent::__construct ();
		require_once APP_LIB_PATH . 'campLib.php';
		$this->campLib = new CampLib ();
		$this->adminGrand = AdminSession::getAdminSessionInfo ();
		AdminVisitor::checkGrant ( 'camp' );
	}
	
	public function gradeedit() {
		ViewData::$form_data = new GradeClass ();
		ViewData::$form_hint = new GradeClass ();
		if (isset ( $_GET ['gradeId'] )) {
			ViewData::$form_data = $this->campLib->getGradeByGradeId ( $_GET ['gradeId'] );
		}
		if ($_POST) {
			$this->campLib->checkGradeForm ();
			if (! BaseAction::isObjectEmpty ( ViewData::$form_hint )) {
				BaseAction::loadView ( "admin/campGradeEdit" );
			}
			try {
				$this->campLib->setGradeLogic ();
				Header ( "Location:  " . siteUrl ( 'grade/campgradelist' ) . "" );
			} catch ( Exception $e ) {
				ViewData::$form_hint->Message = $e->getMessage ();
			}
		}
		BaseAction::loadView ( 'admin/campGradeEdit' );
	}
	
	public function gradedel() {
		ViewData::$form_data->isHaveDelGrant=FALSE;
		$adminInfo = AdminSession::getAdminSessionInfo ();
		if($adminInfo['AdminName']!='admin'){
			BaseAction::adminError ( "您没有权限操作" );
		}
		
		if (! isset ( $_GET ['gradeId'] )) {
			BaseAction::adminError ( "请不要非法访问" );
		}
		$this->campLib->delGradeByGradeId ( $_GET ['gradeId'] );
		BaseAction::adminSuccess ( "删除成功", siteUrl ( 'grade/campgradeList' ) );
	}
	
	public function studentlist() {
		$where = "GradeId=" . $_GET ['gradeId'] ." and RegistStatus >=1";
		ViewData::$form_data->studentList = $this->campLib->getStudentList ( $where );
		BaseAction::loadView ( 'admin/campStudentList' );
	}
	public function studentexportexcel() {
		if (isset ( $_POST ['Id'] ) && isset ( $_GET ['menu'] )) {
			if ($_GET ['menu'] == 'exportExcel') {
				$this->campLib->exportExcel ( $_POST ['Id'] );
			}
		}
		BaseAction::adminError ( "请不要非法操作" );
	}
	public function studentedit() {
		if (! isset ( $_GET ['studentId'] )) {
			BaseAction::adminError ( "请不要非法访问" );
		}
		ViewData::$form_data = $this->campLib->getById ( $_GET ['studentId'] );
		ViewData::$title = "学生信息修改";
		ViewData::$form_hint = new RegisteCampClass ();
		if ($_POST) {
			$this->campLib->checkEditForm ();
			if (! BaseAction::isObjectEmpty ( ViewData::$form_hint )) {
				BaseAction::loadView ( "admin/campStudentEdit" );
			}
			try {
				$this->campLib->editLogic ( $_GET ['studentId'] );
				Header ( "Location:  " . siteUrl ( 'camp/studentlist?gradeId=' . $_GET ['gradeId'] ) );
				BaseAction::adminSuccess ( "修改成功", siteUrl ( 'camp/studentedit?gradeId=' . $_GET ['gradeId'] . '&studentId=' . $_GET ['studentId'] . '' ) );
			} catch ( Exception $e ) {
				ViewData::$form_hint->Message = $e->getMessage ();
			}
		}
		
		BaseAction::loadView ( "admin/campStudentEdit" );
	}
	
	public function payment() {
		if (! isset ( $_GET ['studentId'] )) {
			BaseAction::adminError ( "请不要非法访问" );
		}
		ViewData::$form_data = $this->campLib->getById ( $_GET ['studentId'] );
		ViewData::$form_hint = new RegisteCampClass ();
		if ($_POST) {
			$this->campLib->checkPaymentForm ();
			if (! BaseAction::isObjectEmpty ( ViewData::$form_hint )) {
				BaseAction::loadView ( "admin/campStudentPayment" );
			}
			try {
				$this->campLib->editPaymentLogic ( $_GET ['studentId'] );
				BaseAction::adminSuccess ( "修改成功", siteUrl ( 'camp/studentlist' ) . '?gradeId=' . $_GET ['gradeId'] );
			} catch ( Exception $e ) {
				ViewData::$form_hint->Message = $e->getMessage ();
			}
		}
		BaseAction::loadView ( "admin/campStudentPayment" );
	}
	public function dayin() {
		if (! isset ( $_GET ['studentId'] )) {
			BaseAction::adminError ( "请不要非法访问" );
		}
		ViewData::$form_data = $this->campLib->getById ( $_GET ['studentId'] );
		ViewData::$form_hint = new RegisteCampClass ();
		BaseAction::loadView ( "admin/campStudentView" );
	}
	
	public function studentdel() {
		if (! isset ( $_GET ['studentId'] )) {
			BaseAction::adminError ( "请不要非法访问" );
		}
		$this->campLib->delStudentByStudentId ( $_GET ['studentId'] );
		BaseAction::adminSuccess ( "删除成功", siteUrl ( 'camp/studentlist?gradeId=' . $_GET ['gradeId'] ) );
	}
	
	public function delCheckStudent() {
		try {
			if (isset ( $_POST ['Id'] ) && isset ( $_GET ['menu'] )) {
				if ($_GET ['menu'] == 'delCheck') {
					$this->campLib->delCheckStudent ( $_POST ['Id'] );
					BaseAction::adminSuccess ( "删除成功", siteUrl ( 'camp/studentlist?gradeId=' . $_GET ['gradeId'] ) );
					exit ();
				}
			}
			BaseAction::adminError ( "请不要非法操作" );
		} catch ( Exception $e ) {
			BaseAction::adminError ( $e->getMessage ());
		}
	}
}